﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Biz_Dal.Dal;

namespace Biz_Dal.Biz
{
    public class BizKhachHang
    {
        #region "Khởi tạo"
        public BizKhachHang()
        { 
        
        }

        public BizKhachHang(int _idUser)
        {
            this._idUser = _idUser;
        }

        public BizKhachHang(int _idUser, string _tenDangNhap, string _matKhau, string _hoTen, string _email, string _diaChi, string _dienThoai, bool _laQuanTri, bool _laUserXau, double _taiKhoan)
        {
            this._idUser = _idUser;

            this._tenDangNhap = _tenDangNhap;

            this._matKhau = _matKhau;

            this._hoTen = _hoTen;

            this._email = _email;

            this._diaChi = _diaChi;

            this._dienThoai = _dienThoai;

            this._laQuanTri = _laQuanTri;

            this._laUserXau = _laUserXau;

            this._taiKhoan = _taiKhoan;
        }
        #endregion


        #region "Thuộc tính"

        private int _idUser;

        private string _tenDangNhap;

        private string _matKhau;

        private string _hoTen;

        private string _email;

        private string _diaChi;

        private string _dienThoai;

        private bool _laQuanTri;

        private bool _laUserXau;

        private double _taiKhoan;

        public int idUser
        {
            get
            {
                return this._idUser;
            }
            set
            {

                this._idUser = value;
            }
        }

        public string tenDangNhap
        {
            get
            {
                return this._tenDangNhap;
            }
            set
            {
                this._tenDangNhap = value;
            }
        }

        public string matKhau
        {
            get
            {
                return this._matKhau;
            }
            set
            {
                this._matKhau = value;
            }
        }

        public string hoTen
        {
            get
            {
                return this._hoTen;
            }
            set
            {
                this._hoTen = value;
            }
        }

        public string email
        {
            get
            {
                return this._email;
            }
            set
            {
                this._email = value;
            }
        }


        public string diaChi
        {
            get
            {
                return this._diaChi;
            }
            set
            {
                this._diaChi = value;
            }
        }

        public string dienThoai
        {
            get
            {
                return this._dienThoai;
            }
            set
            {
                this._dienThoai = value;
            }
        }


        public bool laQuanTri
        {
            get
            {
                return this._laQuanTri;
            }
            set
            {
                this._laQuanTri = value;
            }
        }

        public bool laUserXau
        {
            get
            {
                return this._laUserXau;
            }
            set
            {
                this._laUserXau = value;
            }
        }

        public double taiKhoan
        {
            get
            {
                return this._taiKhoan;
            }
            set
            {
                this._taiKhoan = value;
            }
        }

        #endregion


        #region "Login"
        public static List<BizKhachHang> Login(string user, string pass)
        {
            try
            {
                return DalKhachHang.Login(user, pass);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public static List<BizKhachHang> LoginKhachHang(string user, string pass)
        {
            try
            {
                return DalKhachHang.LoginKhachHang(user, pass);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public static List<BizKhachHang> LoginAdmin(string user, string pass)
        {
            try
            {
                return DalKhachHang.LoginAdmin(user, pass);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }
        #endregion

        public static List<BizKhachHang> getListKhachHangAll()
        {
            try
            {
                return DalKhachHang.getListKhachHangAll();
            }
            catch
            {
                throw new Exception("Không lấy được danh sách người dùng!");
            }
        }

        public static BizKhachHang getKhachHangByID(int ID)
        {
            try
            {
                return DalKhachHang.getKhachHangByID(ID);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public static List<BizKhachHang> getKhachHangByUserName(string name)
        {
            try
            {
                return DalKhachHang.getKhachHangByUserName(name);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public static List<BizKhachHang> getListKhachHangByName(string name)
        {
            try
            {
                return DalKhachHang.getListKhachHangByName(name);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public static List<BizKhachHang> getListLikeKhachHangByName(string name)
        {
            try
            {
                return DalKhachHang.getListLikeKhachHangByName(name);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public static int CountListKH()
        {
            try
            {
                return DalKhachHang.CountListKH();
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        //lấy id mới
        public static int IdMaxKhachHang()
        {
            try
            {
                return DalKhachHang.IdMaxKhachHang();
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        #region "Thêm - Xoá - Sửa"
        public static int insertKhachHang(BizKhachHang DalKhachHangDTO)
        {
            try
            {
                DalKhachHang.insertKhachHang(DalKhachHangDTO);
                return 0;
            }
            catch
            {
                return 1;
            }
        }

        public static void deleteKhachHang(int idDalKhachHangachHang)
        {
            try
            {
                DalKhachHang.deleteKhachHang(idDalKhachHangachHang);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public void updateKhachHang()
        {
            try
            {
                DalKhachHang.updateKhachHang(this);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }
        #endregion

        public static void suaUserBad(int id, bool badUser, bool adminn)
        {
            try
            {
                DalKhachHang.suaUserBad(id,badUser,adminn);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }
    }
}
